import requests
import json
import os
api_key=os.getenv("DASHSCOPE_API_KEY")
url = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"
headers = {
    "authorization": f"bearer {api_key}",
    "content-type":"application/json"
}
data = {
    "model": "qwen-plus",
    "messages": [  
        {"role": "system","content": "you are a helpful assistant."},
        {"role":"user","content":"你是谁"}
    ]
}
response = requests.post(url, headers=headers, json=data)

try:
    response.raise_for_status()
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except requests.exceptions.RequestException as e:
    print(f"请求出错：{e}")
    if response.text:
        print(f"错误详情：{response.text}")
